Date.prototype.format = function(fmt) {
    var o = {
        "M+" : this.getMonth()+1,                 //月份
        "d+" : this.getDate(),                    //日
        "h+" : this.getHours(),                   //小时
        "m+" : this.getMinutes(),                 //分
        "s+" : this.getSeconds(),                 //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S"  : this.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt)) {
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
    for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
    return fmt;
}


var vm = new Vue({
    el:"#ljw",
    data:{
        pageNum:1,
        pageSize:5,
        Id:"",
        danju:"",
        quyu:"",
        listPr:"",


        total:0,
        //总页数
        pages:0,
        isFirstPage:false,
        isLastPage:false,
        hasPreviousPage:false,
        hasNextPage:false,
        //所有导航页号
        navigatepageNums:[],
    },
    methods: {
        show(pageNum, pageSize) {
            var json = {
                pageNum: pageNum,
                pageSize: pageSize,
                id: this.Id,
                orderStaId: this.danju,
                woseId: this.quyu
            }
            JSON.stringify(json)
            axios.post('/purchase/listPr', json,{

            }).then(res=>{
                vm.listPr=res.data.obj.list
                this.pageNum=parseInt(res.data.obj.pageNum);
                this.pageSize=parseInt(res.data.obj.pageSize);
                this.total=parseInt(res.data.obj.total);
                this.pages=parseInt(res.data.obj.pages);
                this.isFirstPage=res.data.obj.isFirstPage;
                this.isLastPage=res.data.obj.isLastPage;
                this.hasPreviousPage=res.data.obj.hasPreviousPage;
                this.hasNextPage=res.data.obj.hasNextPage;
                this.navigatepageNums=res.data.obj.navigatepageNums;
            }).catch(err=>{

            })
        },
        //上一页
        qian(){
            if(this.hasPreviousPage==true){
                // alert("上一页")
                //表示有上一页
                this.show(this.pageNum-1,this.pageSize);
            }
        },
        //下一页
        hou(){
            if(this.hasNextPage==true){
                this.show(this.pageNum+1,this.pageSize);
            }
        },
        sc(code,orderSta) {
            if (orderSta == 1) {
                var i = {
                    id: code,
                    orderStaId: 14
                }
                axios.post("/purchase/updaPr", i, {}).then(res => {
                    alert("执行成功")
                    location.reload()
                })
                alert(2)
            } else {
                var i = {
                    id: code,
                    orderStaId: 14
                }
                alert(1)
                axios.post("/purchase/updaPr", i, {}).then(res => {


                    var crk = {
                        relCode: code,
                        pageNum: 1,
                        pageSize: 1,
                    }
                    JSON.stringify(crk)
                    axios.post('/wares/getStock_order', crk, {
                        'Content-Type': 'multipart/form-data'
                    }).then(res => {
                        vm.listck = res.data.obj.list
                        var code = vm.listck[0].code
                        var status = vm.listck[0].statusId
                        var single = vm.listck[0].single
                        var rk = {
                            bStatus: status,
                            status: 14,
                            code: code,
                            type: 21,
                            single: single,
                            subDate: new Date().format("yyyy-MM-dd hh:mm:ss"),
                            verifier: single,
                            verifyDate: new Date().format("yyyy-MM-dd hh:mm:ss"),
                        }
                        JSON.stringify(rk)
                        axios.post('/wares/nextStock_order', rk, {
                            'Content-Type': 'multipart/form-data'
                        }).then(res => {
                            alert("执行成功")
                            location.reload();
                        })

                    })


                })
            }


        },
    },

    mounted(){
        this.show(this.pageNum,this.pageSize)
    }
})